package com.dysm.spring.security.resource.controller;

import com.dysm.spring.security.resource.annotion.Anonymous;
import com.dysm.spring.security.resource.config.context.UserContext;
import com.dysm.spring.security.resource.config.context.UserContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class BusController {

    private final Logger LOG = LoggerFactory.getLogger(this.getClass());

    @PostMapping(path = "/user/getUser")
    public ResponseEntity<UserContext> getUser(HttpServletRequest request, @RequestBody Integer param) {
        LOG.info("request.getRequestURI：{},param:{}", request.getRequestURI(), param);
        return ResponseEntity.ok(UserContextUtil.get());
    }

    @Anonymous
    @PostMapping(path = "/user/getUserByAnonymous")
    public ResponseEntity<UserContext> getUserByAnonymous() {
        return ResponseEntity.ok(UserContextUtil.get());
    }
}
